<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="Pragma" content="no-cache" />
		<meta http-equiv="Cache-Control" content="no-cache" />
		<meta http-equiv="Expires" content="0" />
		<meta http-equiv="X-UA-Compatible" content="E=edge;chrome=1" />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<title>嘉华金融</title>
        <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/reset.css">
	    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/weui.min.css">
	    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/index.css">
	    <script type="text/javascript" src="<%=path%>/static/js/jquery-3.2.1.min.js"></script>
	    <script type="text/javascript" src="<%=path%>/static/layer/layer.js"></script>
	    <script type="text/javascript" src="<%=path%>/static/js/jquery-3.2.1.min.js"></script>
        <script type="text/javascript" src="<%=path%>/static/js/index.js"></script>
    </head>
    <style>
    .error-m {
	   height: 1rem;
	   line-height: 1rem;
	   margin:1.2rem 0 0.5rem;
	   font-size: 0.9rem;
	   color: #ff0124;
	   text-align: center;
    }
    .content {
       font-size: 0.9rem;
       color: #ff0124;
       text-align: left;
       padding: 0.5rem 1.4rem;
     }
    </style>
<body>
    <div>
        <div class="header">
            <div><div class="back"></div></div>
            <div>现金提现</div>
            <div><!-- <div class="user-img"></div> --></div>
        </div>
        <div class="content">每人每日只可提现一次，且每月不得超过五次，超过后每次收取两元手续费。</div>
        <input id="openid" type="hidden" value="${buserInfo.openid}"></input>
        <input id="monthCount" type="hidden" value="${monthCount}"></input>
        <input id="dayCount" type="hidden" value="${dayCount}"></input>
        <div class="main">
            <div class="cash-present-wrap">
                <div class="weui-cells">
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">钱包金额</label></div>
                        <div class="weui-cell__bd">
                            <p class="hash-cash">${buserInfo.income}</p>
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">提现金额</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input comp-name" pl="输入金额" type="number" onkeyup="clearNoNum(this)" oninput="change()" >
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><p>提现银行卡:</p></div>  
                    </div>
                  <c:forEach items="${bCards}" var="item" varStatus="vs">
                        <div class="weui-cell">
                        <div class="weui-cell__hd">
                            <p>${item.source}</p>
                            <p>${item.cardIdCopy}</p>
                        </div>
                        <c:choose> 
	                        <c:when test="${vs.index==0}">
	                         <div class="weui-cell__bd"></div>
		                        <div class="weui-cell__bd"></div>
			                        <div class="weui-cell__ft">
			                            <div class="choose-circle">
			                                <div class="choose circle-color">
			                                     <input id = "cardId" value="${item.cardId}" type="hidden">
			                                </div>
			                            </div>
			                        </div>    
	                         </div>
	                        </c:when>
	                        <c:otherwise>
	                         <div class="weui-cell__bd"></div>
	                           <div class="weui-cell__ft">
	                               <div class="choose-circle">
	                                   <div class="choose">
	                                    <input id = "cardId" value="${item.cardId}" type="hidden">
	                                   </div>
	                               </div>
	                           </div>  
	                         </div>
	                        </c:otherwise>
                         </c:choose> 
                  </c:forEach>
                    <div class="weui-cell">
                        <div class="add-card">
                            <div>
                                <div class="add-img left"></div>
                                <div class="left">添加银行卡</div>
                            </div>
                        </div>
                    </div>
                </div>
                 <li class="error-m">
                    <div class="error-content"></div>
                 </li>
                <div class="cash-btn-wrap">
                    <div class="cash-btn">提交</div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
      var path ="<%=path%>";
       $(function(){
    	  var dayCount=parseInt($("#dayCount").val())
    	  var monthCount=parseInt($("#monthCount").val())
    	  if(dayCount>=1){
    		  layer.alert('当日提现次数已达上线', {icon: 1,closeBtn: 0}, function(index) {
    			  layer.close(index)
    			  window.location=path+"/member/memberCenter.html";
              });  
    	  }else if(monthCount>=5){
              layer.alert('已超过每月5次限定提现次数，继续操作将收取2元手续费', {icon: 1,closeBtn: 0}, function(index) {
                  layer.close(index)
              });  
          }
    	  
       });     
        
        $(".choose-circle").on('touchstart',function() {
            $(".choose").each(function() {
                $(this).removeClass("circle-color");
            })
            $(this).children().addClass("circle-color");
        })
       function clearNoNum(obj){  
	       //第一个字符是小数点 的情况.  
	       if(obj.value !=''&& obj.value.substr(0,1) == '.'){  
	           obj.value="";  
	       }  
	       obj.value = obj.value.replace(/^0*(0\.|[1-9])/, '$1');//解决 粘贴不生效  
	       obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
	       obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的       
	       obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");      
	       obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数       
	       if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额  
	           if(obj.value.substr(0,1) == '0' && obj.value.length == 2){  
	               obj.value= obj.value.substr(1,obj.value.length);      
	           }  
	       }      
    } 
        
    var income = parseFloat("${buserInfo.income}")    
    function change(){
    	if($(".comp-name").val()==""){
    		$(".cash-btn").css("background","#dedede");
    		$(".error-content").text("");
    	}else if(parseFloat($(".comp-name").val())<100){
            $(".cash-btn").css("background","#dedede");
            $(".error-content").text("提现金额需大于等于100元"); 
    	}else if(parseFloat($(".comp-name").val())>income){
    		$(".cash-btn").css("background","#dedede");
    		$(".error-content").text("提现金额大于钱包金额");    		
    	}else{
    		$(".error-content").text("");
    		$(".cash-btn").css("background","#fedf44");
    	}
    } 
    
    var flag=true;
    $(".cash-btn").on("touchstart",function(){
    	var cardId=$(".circle-color").find("input").val();
    	if(flag=true){
    		flag=false;
    		if(income<100){
    			 $(".error-content").text("钱包金额小于100元，无法提现");
                 flag=true;
                 return false;
    		}else if(cardId==null){
    			$(".error-content").text("请先绑定银行卡");
                flag=true;
                return false;
    		}else if($(".comp-name").val()==""){
                $(".error-content").text("提现金额不能为空");
                flag=true;
                return false;
            }else if(parseFloat($(".comp-name").val())<100){
                $(".error-content").text("提现金额需大于等于100元");
                flag=true;
                return false;
            }else if(parseFloat($(".comp-name").val())>income){
                $(".error-content").text("提现金额大于钱包金额");
                flag=true;
                return false;
            }else{
               $.ajax({
            	   url : path+"/member/insertCash.html",
                   data: {
                	   number:$(".comp-name").val(),
                	   card:cardId,
                	   openid:$("#openid").val(),
                	   monthCount:$("#monthCount").val()   
                   },
                   type : "POST",
                   datatype : "json",
                   async: false, 
                   success : function(datas) {
                       var json =JSON.parse(datas);
                       layer.msg(json.msg, {time: 2000},function(){
                    	   flag=true; 
                    	   if(json.code==200){
                    		   window.location=path+"/member/memberCenter.html";
                    	   }
                       });
                   },
                   error:function(datas){
                	   layer.msg("提交失败", {time: 2000},function(){                          
                           flag=true;
                       });
                   }
               })
            }
    	}
    });
    
    $(".left").click(function(){
        window.location=path+"/member/addCard.html";
    });
    
    $('.back').on('click', function () {
        window.location=path+"/member/memberCenter.html";
    });
</script>
</body>
</html>
